<template>
  <div class="admin-main">
    <el-container>
      <el-header class="header">
        <div class="header-left">
          <i class="el-icon-s-operation menu-toggle" @click="toggleCollapse" />
          <span class="logo">健身房管理系统</span>
        </div>

        <!-- ✅ 右侧整体布局区域 -->
        <div class="header-right">
          <el-input v-model="searchText" size="small" placeholder="搜索..." class="search-input" />
          <el-button size="small" type="primary" icon="el-icon-search">查询</el-button>
          <el-button
              type="text"
              @click="handleLogout"
              class="admin-avatar-button"
          >
            <el-avatar size="small" style="background-color: #409EFF; font-size: 6px;">
              管理员
            </el-avatar>
          </el-button>
        </div>
      </el-header>

      <el-container>
        <el-aside :width="isCollapse ? '64px' : '200px'" class="aside">
          <el-menu :default-active="$route.path" router :collapse="isCollapse" class="menu">
            <el-sub-menu index="1">
              <template #title>
                <span>快速查询</span>
              </template>
              <el-menu-item index="/AdminMain/SelMemberByCard">
                <i class="el-icon-s-order"></i>会员卡查询
              </el-menu-item>
            </el-sub-menu>
            <el-sub-menu index="2">
              <template #title>
                <span>管理</span>
              </template>
              <el-menu-item index="/AdminMain/MemberManager">
                <i class="el-icon-user"></i>会员管理
              </el-menu-item>
              <el-menu-item index="/AdminMain/EmployeeManager">
                <i class="el-icon-s-custom"></i>员工管理
              </el-menu-item>
              <el-menu-item index="/AdminMain/EquipmentManager">
                <i class="el-icon-s-platform"></i>器材管理
              </el-menu-item>
              <el-menu-item index="/AdminMain/ClassManager">
                <i class="el-icon-date"></i>课程管理
              </el-menu-item>
              <el-menu-item index="/AdminMain/GoodsManager">
                <i class="el-icon-date"></i>商品管理
              </el-menu-item>
              <el-menu-item index="/AdminMain/GoodsOrderManager">
                <i class="el-icon-date"></i>订单管理
              </el-menu-item>
            </el-sub-menu>
            <el-sub-menu index="3">
              <template #title>
                <span>链接</span>
              </template>
              <el-menu-item index="/projectLink">
                <i class="el-icon-link"></i>项目地址
              </el-menu-item>
            </el-sub-menu>
          </el-menu>
        </el-aside>

        <el-container direction="vertical" class="content-container">
          <router-view></router-view>
          <el-footer class="footer">
            <div>你好！管理员</div>
            <div>Copyright © Curry 2025</div>
          </el-footer>
        </el-container>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessageBox } from 'element-plus'

const router = useRouter()
const searchText = ref('')
const isCollapse = ref(false)

const toggleCollapse = () => {
  isCollapse.value = !isCollapse.value
}

const handleLogout = () => {
  ElMessageBox.confirm('是否确认退出登录？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning',
  })
      .then(() => {
        router.push('/AdminLogin')  // 可改为 /login
      })
      .catch(() => {})
}
</script>

<style scoped>
html, body, #app, .admin-main {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.el-container {
  height: 100%;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #343a40;
  color: white;
  height: 50px;
  padding: 0 15px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  font-weight: bold;
  font-size: 16px;
}

.menu-toggle {
  font-size: 20px;
  cursor: pointer;
}

.search-input {
  width: 200px;
}

.admin-avatar-button {
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
}

.aside {
  background: #ffffff;
  border-right: 1px solid #ddd;
}

.menu {
  font-size: 14px;
  border-right: none;
}

.content-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.footer {
  height: 70px;
  background: #ffffff;
  color: #6c757d;
  text-align: center;
  font-size: 13px;
  padding-top: 20px;
}
</style>
